class Set {

  constructor () {
    this.dataStore = []
  }

  add (data) {
    if (this.dataStore.indexOf(data) > -1) return false
    this.dataStore.push(data)
    return true
  }

  remove (data) {
    let pos = this.dataStore.indexOf(data)
    if (pos === -1) return false
    this.dataStore.splice(pos, 1)
    return true
  }

  /**
   *  并集
   * @param set
   * @returns {Set}   返回合并两个集合的新集合
   */
  union (set) {
    let tempSet = new Set()
    for (let i = 0; i < this.size(); i++) {
      tempSet.add(this.dataStore[i])
    }
    for (let y = 0; y < set.size(); y++) {
      if (!tempSet.contains(set.dataStore[y])) {
        tempSet.add(set.dataStore[y])
      }
    }
    return tempSet
  }

  /**
   *  交集
   * @param set
   * @returns {Set}  返回两个集合中共同的数据的新集合
   */
  intersect (set) {
    let tempSet = new Set()
    for (let i = 0, data; data = this.dataStore[i++];) {
      if (set.contains(data)) {
        tempSet.add(data)
      }
    }
    return tempSet
  }

  /**
   *  差集
   * @param set
   * @returns {Set}  返回只在当前集合中的数据的新集合
   */
  difference (set) {
    let tempSet = new Set()
    for (let i = 0, data; data = this.dataStore[i++];) {
      if (!set.contains(data)) {
        tempSet.add(data)
      }
    }
    return tempSet
  }

  /**
   *  判断当前集合是否是其他集合的子集
   * @param set
   * @returns {boolean}
   */
  subset (set) {
    if (this.size() > set.size()) return false
    for (let i = 0, data; data = this.dataStore[i++];) {
      if (!set.contains(data)) {return false}
    }
    return true
  }

  contains (data) {return this.dataStore.indexOf(data) > -1 ? true : false}

  show () {return this.dataStore}

  size () {
    return this.dataStore.length
  }

}

function print (data) {
  console.log(data)
}

var cis = new Set()
var it = new Set()
cis.add('Clayton')
cis.add('Jennifer')
cis.add('Danny')
it.add('Bryan')
it.add('Clayton')
it.add('Jennifer')
var diff = new Set()
diff = cis.difference(it)
print('[' + cis.show() + '] difference [' + it.show()
  + '] -> [' + diff.show() + ']')
